<?php
require('header.php');
$sql1 = "SELECT * FROM games";
$sql2 = "SELECT * FROM game_links";
$r1 = mysql_query($sql1) or die('Could not find any games in database.');
$r2 = mysql_query($sql2) or die('Could not find any game links in database.');
?>
    <h1>Games that must be Played!</h1>
      <hr>

      <div class="accordion-group">
      <?php
      $i=0;
      while($game=mysql_fetch_assoc($r1)) {
        echo '<div class="accordion-heading">';
        echo '<a href="#collapse'.$i.'" data-parent="#accordion2" data-toggle="collapse" class="accordion-toggle">'.$game['game'].'</a></div>';
        echo '<div class="accordion-body collapse in" id="collapse'.$i.'">';
        echo '<div class="accordion-inner">';
        while($link=mysql_fetch_assoc($r2)) {
          if ($game['game_id'] == $link['game_id']) {
            echo $link['link'].'<br />';
          }
        }
        echo '</div></div>';
        if(mysql_num_rows($r2)>0) {
          mysql_data_seek($r2, 0);
        }
        
        $i+=1;
      }
      ?>
      </div>

    </div> <!-- /container -->

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="assets/js/jquery.js"></script>
    <script src="assets/js/bootstrap-transition.js"></script>
    <script src="assets/js/bootstrap-alert.js"></script>
    <script src="assets/js/bootstrap-modal.js"></script>
    <script src="assets/js/bootstrap-dropdown.js"></script>
    <script src="assets/js/bootstrap-scrollspy.js"></script>
    <script src="assets/js/bootstrap-tab.js"></script>
    <script src="assets/js/bootstrap-tooltip.js"></script>
    <script src="assets/js/bootstrap-popover.js"></script>
    <script src="assets/js/bootstrap-button.js"></script>
    <script src="assets/js/bootstrap-collapse.js"></script>
    <script src="assets/js/bootstrap-carousel.js"></script>
    <script src="assets/js/bootstrap-typeahead.js"></script>
    <script>
    $(function () {
      $(".collapse").collapse()
    });

    </script>
  </body>
</html>
